<!DOCTYPE html>
<html>
<!--
author:lvlu
date:2018-07
desc:this demo is about blog. PLEASE NOTE:If you have trouble running it ,try any of the other demos or connect with auther.
A ny individuals and organizations and not for commercial use, professiona website for customized web site.
-->
<head lang="en">
    <meta charset="UTF-8">
    <title>我的订单 - 皮爷の商城</title>
    <link rel="stylesheet" href="../static/css/index.css">
    <link href="../static/css/myOrder.css" rel="Stylesheet" />
    <link href="../static/css/personage.css" rel="stylesheet" />
    <link rel="icon" href="../static/images/index/py.ico">
    <script src="../static/js/init.js"></script>
    <style>
    .msg-default {
        background-color: #999;
    }
    .msg-error {
        background-color: #d00;
    }
    .msg-success {
      background-color: #0d0;
    }
    /* .confirm_hint {
        background-color: #999;
    } */
    </style>
</head>

<body>
    <!-- 页面顶部-->
    <header id="header"></header>
    <!-- 我的订单导航栏-->
    <div id="nav_order">

    </div>
    <!--我的订单内容区域 #container-->
    <div id="container" class="clearfix">
        <!-- 左边栏-->
        <div id="leftsidebar_box" class="lf">
            <div class="line"></div>
            <dl class="my_order">
                <dt onClick="changeImage()">我的订单
                    <img src="../static/images/myOrder/myOrder2.png">
                </dt>
                <dd class="first_dd"><a href="myOrder.html">全部订单</a></dd>
                <dd>
                    <a href="#">
                        待付款
                        <span>
                            <!--待付款数量--></span>
                    </a>
                </dd>
                <dd>
                    <a href="#">
                        待收货
                        <span>
                            <!--待收货数量-->1</span>
                    </a>
                </dd>
                <dd>
                    <a href="#">
                        待评价<span>
                            <!--待评价数量--></span>
                    </a>
                </dd>
                <dd>
                    <a href="#">退货退款</a>
                </dd>
            </dl>

            <dl class="footMark">
                <dt onClick="changeImage()">我的优惠卷<img src="../static/images/myOrder/myOrder1.png"></dt>
            </dl>
            <dl class="address">
                <dt>收货地址<img src="../static/images/myOrder/myOrder1.png"></dt>
                <dd><a href="addressAdmin.html">地址管理</a></dd>
            </dl>
            <dl class="count_managment">
                <dt onClick="changeImage()">帐号管理<img src="../static/images/myOrder/myOrder1.png"></dt>
                <!--<dd class="first_dd"><a href="personage.html">我的信息</a></dd>-->
                <dd><a href="personal_password.html">安全管理</a></dd>
            </dl>
        </div>
        <!-- 右边栏-->
        <!--个人信息头部-->
        <div class="rightsidebar_box rt">
            <div class="rs_header">
                <!--<span><a href="personage.html">我的信息</a></span>-->
                <span class="rs_header_active"><a href="personal_password.html">安全管理</a></span>
            </div>

            <!--安全管理 -->
            <div class="rs_content">
                <p class="change_password_title">更改密码</p>
                <div class="new_password">
                    <span class="word">输入旧密码：</span>
                    <input required type="password" minlength="6" maxlength="12" name="upwd" id="upwd" />
                    <span class="change_hint"></span>
                </div>
                <div class="new_password">
                    <span class="word">输入新密码：</span>
                    <input required type="password" minlength="6" maxlength="12" name="npwd" id="npwd" />
                    <span class="change_hint"></span>
                </div>
                <div class="confirm_password">
                    <span class="word">确认新密码：</span>
                    <input required type="password" minlength="6" maxlength="12" name="rpwd" id="rpwd" />
                    <span class="confirm_hint"></span>
                </div>
                <div class="save_password">
                    保存更改
                </div>
            </div>


        </div>
    </div>

    <footer id="footer"></footer>
</body>
<script type="text/javascript" src="../static/js/jquery-3.1.1.min.js"></script>
<script src="../static/js/index.js"></script>
<script src="../static/js/jquery.page.js"></script>
<script type="text/javascript" src="../static/js/order.js"></script>
<script>
    npwd.onfocus = function () {
        this.nextElementSibling.innerHTML = '密码长度在6到12位之间';
        this.nextElementSibling.className = 'msg-default';
    }
    rpwd.onfocus = function () {
        this.nextElementSibling.innerHTML = '密码长度在6到12位之间';
        this.nextElementSibling.className = 'msg-default';
    }
    npwd.onblur = function () {
        if (this.validity.valueMissing) {
            this.nextElementSibling.innerHTML = '密码不能为空';
            this.nextElementSibling.className = 'msg-error';
            this.setCustomValidity('密码不能为空');
        } else if (this.validity.tooShort) {
            this.nextElementSibling.innerHTML = '密码长度在尽量别少于6位';
            this.nextElementSibling.className = 'msg-error';
            this.setCustomValidity('密码长度在尽量别少于6位');
        } else {
            this.nextElementSibling.innerHTML = '密码格式正确';
            this.nextElementSibling.className = 'msg-success';
            this.setCustomValidity('');
        }
    }
    rpwd.onblur = function () {
        if ($('#npwd').val() === $('#rpwd').val()) {
            this.nextElementSibling.innerHTML = '两次密码输入正确';
            this.nextElementSibling.className = 'msg-success';
            this.setCustomValidity('');
        } else if ($('#npwd').val() != $('#rpwd').val()) {
            this.nextElementSibling.innerHTML = '两次密码输入错误';
            this.nextElementSibling.className = 'msg-error';
        }
    }
</script>
<script>
var username= window.localStorage.getItem('dashop_user')
    $(".save_password").click(function () {
	if ($('#npwd').val()==$('#rpwd').val()) {
		$.ajax({
			type: 'post',
            url: baseUrl+'/v1/users/'+username+'/password',
            contentType:'application/json',
			datatype: 'json',
			data: JSON.stringify({"oldpassword": $('#upwd').val(),"password1": $('#npwd').val(),"password2":$('#rpwd').val()}),
            beforeSend:function(request){
				request.setRequestHeader("authorization",localStorage.getItem('dashop_token'))
			},
            success: function (response) {
			    if(response.code == 403){
							alert('用户认证已过期，请重新登录');
							window.localStorage.removeItem('dashop_user');
							window.localStorage.removeItem('dashop_token');
							window.localStorage.removeItem('dashop_count');
							location.href = 'login.html'
						}
				if (response.code==200) {
					alert('密码修改成功')
					$('#upwd').val('')
					$('#npwd').val('')
                    $('#rpwd').val('')
                    window.localStorage.clear()
                    location.href = 'login.html'
				}else{
                    alert(response.error)
                }
			},
		})
	} else {
		alert("请再次验证输入密码是否一致！");
	}
})
</script>

</html>
